<script>
import outMain from "@/components/outMain.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { signRecord, czStatusCheck } from "@/http/api";
export default {
  components: { outMain },
  name: "",
  data() {
    return {
      tagArr: [
        { label: "企业端", value: 1 },
        { label: "船东端", value: 2 },
      ],
      statusArr: [
        { label: "全部", value: "" },
        { label: "在职", value: "1" },
        { label: "离职", value: "2" },
      ],
      ctrlArr: [
        { label: "全部", value: "" },
        { label: "待处理", value: "1" },
        { label: "已标记", value: "2" },
        { label: "已忽略", value: "3" },
      ],
      tableData: [],
      queryData: {
        real_name: "",
        type: 1,
        page: 1,
        is_sup_bj: "",
        zz_status: "",
        per_page: 10,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    serchFn() {
      this.queryData.page = 1;
      this.getData();
    },
    checkStatus(row, type) {
      let str = type == 2 ? "已标记" : "已忽略";
      ElMessageBox.confirm(
        `确定将选择的记录操作状态更改为${str}?`,
        "操作提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {
        let data = {
          id: row.id,
          type: this.queryData.type,
          status: type,
        };
        czStatusCheck(data).then((res) => {
          if (res.data.code == 1) {
            ElMessage({
              type: "success",
              message: "操作成功",
            });
            this.getData();
          }
        });
      });
    },
    detailFn(row) {
      this.$router.push({
        path: "/salaSignDetail",
        query: {
          id: row.id,
          type: this.queryData.type,
          page: this.queryData.page,
        },
      });
    },
    async getData() {
      const { data } = await signRecord(this.queryData);
      if (data.code == 1) {
        this.tableData = data.data.data;
        this.total = data.data.total;
      }
    },
  },
  mounted() {},
  created() {
    this.queryData.page = Number(localStorage.getItem("boot_page")) || 1;

    this.queryData.type = this.$route.query.type || 1;
    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>船员签约记录（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft"></div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.real_name"
                placeholder="请输入船员姓名"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.sign_number"
                placeholder="请输入签约单号"
              />
            </el-form-item>
            <el-form-item>
              <el-select
                v-model="queryData.type"
                @change="serchFn"
                placeholder="请选择船员来源端口"
              >
                <el-option
                  v-for="item in tagArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-select
                clearable
                @change="getData"
                v-model="queryData.zz_status"
                placeholder="请选择船员状态"
              >
                <el-option
                  v-for="item in statusArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-select
                @change="getData"
                clearable
                v-model="queryData.is_sup_bj"
                placeholder="请选择操作状态"
              >
                <el-option
                  v-for="item in ctrlArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="sign_number"
          show-overflow-tooltip
          width="200"
          label="签约单号"
        />
        <el-table-column
          prop="real_name"
          width="120"
          show-overflow-tooltip
          label="船员姓名"
        />
        <el-table-column
          width="150"
          prop="mobile"
          show-overflow-tooltip
          label="手机号"
        />
        <el-table-column prop="qy_cyxz" show-overflow-tooltip label="船员薪资">
          <template #default="{ row }">
            <span
              >{{ row.qy_cyxz }}{{ row.qy_cyxz_dw == 1 ? "元" : "美元" }}</span
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="position_name"
          show-overflow-tooltip
          label="签约岗位"
        />
        <el-table-column label="船员状态">
          <template #default="{ row }">
            <el-tag v-if="row.zz_status == 1">在职</el-tag>
            <el-tag type="info" v-if="row.zz_status == 2">离职</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="SBType" label="操作状态">
          <template #default="{ row }">
            <el-tag type="warning" v-if="row.is_sup_bj == 1">待处理</el-tag>
            <el-tag v-if="row.is_sup_bj == 2">已标记</el-tag>
            <el-tag type="info" v-if="row.is_sup_bj == 3">已忽略</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="lz_time"
          show-overflow-tooltip
          label="离职时间"
        />
        <el-table-column prop="Name" width="140" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div class="greenText ctrlText" @click="detailFn(row)">详情</div>
              <div
                class="blueText ctrlText"
                v-if="row.is_sup_bj == 1"
                @click="checkStatus(row, 2)"
              >
                标记
              </div>
              <div
                class="redText ctrlText"
                v-if="row.is_sup_bj == 1"
                @click="checkStatus(row, 3)"
              >
                忽略
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
